home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / tvtoys04.zip / VESA.PAS < prev    next >
Pascal/Delphi Source File  |  1993-12-07  |  8KB  |  267 lines

  1. (***************************************************************************
  2.   VESA unit
  3.   VESA video mode routines
  4.   PJB October 6, 1993, Internet mail to d91-pbr@nada.kth.se
  5.   Copyright PJB 1993, All Rights Reserved.
  6.   Free source, use at your own risk.
  7.   If modified, please state so if you pass this around.
  8.  
  9.   This unit has been tested in protected mode with a PD VESA TSR.
  10.   UNIVESA.EXE does not implement text mode support, so can't be used
  11.   to test with.
  12.  
  13.   You can overlay this unit if you want to.
  14.  
  15. ***************************************************************************)
  16. unit VESA;
  17. {$B-,O+,T-,X+}
  18. {$IFDEF DPMI} {$G+} {$ENDIF}
  19.  
  20. interface
  21.  
  22.   uses
  23.    {$IFDEF DPMI}
  24.     DPMI, WinAPI,
  25.    {$ENDIF}
  26.     Objects;
  27.  
  28.   type
  29.     Signature = array [0..3] of Char;
  30.     ModeAttr = (Supported, OptionalInfo, BIOSOutput, Color, Graphics);
  31.     AddModeProc = procedure (Mode, Rows, Columns, CharHeight:Word; Color:boolean);
  32.  
  33.     PVesaInfoBlock = ^VesaInfoBlock;
  34.     VesaInfoBlock =
  35.       record
  36.         VesaSignature : Signature;
  37.         VesaVersion   : Word;
  38.         OEMStringPtr  : Pointer;
  39.         Capabilities  : array [0..3] of Byte;
  40.         VideoModePtr  : Pointer;
  41.         Fill          : array [18..255+10] of Byte;
  42.       end;
  43.  
  44.     PVesaModeInfo = ^VesaModeInfo;
  45.     VesaModeInfo =
  46.       record
  47.         Attr       : set of ModeAttr;
  48.         Fill1      : array [1..$11] of Byte;
  49.         Width      : Word;
  50.         Height     : Word;
  51.         CharWidth  : Byte;
  52.         CharHeight : Byte;
  53.         Fill2      : array [$18..$FF+10] of Byte;
  54.       end;
  55.  
  56.   var
  57.     VesaVersion           : Word;
  58.     VesaScanningSupported : Boolean;
  59.     StandardInfoAvailable : Boolean;
  60.  
  61.  
  62.   function  GetVesaInfo(VesaInfo:PVesaInfoBlock):Boolean;
  63.   function  GetVesaModeInfo(Mode:Word; Buffer:PVesaModeInfo):Boolean;
  64.   procedure SetVesaMode(Mode:Word);
  65.   function  GetVesaMode:Word;
  66.   procedure DetectVesaVersion;
  67.   procedure ScanVesaModes(AddMode:AddModeProc);
  68.   function  VesaScanningPossible:Boolean;
  69.  
  70. (***************************************************************************
  71. ***************************************************************************)
  72. implementation
  73.  
  74.   uses
  75.     Video;
  76.  
  77.   const
  78.     VesaSig = 'VESA';
  79.  
  80.  
  81.  
  82.   (*******************************************************************
  83.     Get VESA information (signature, version, video modes)
  84.   *******************************************************************)
  85.   function GetVesaInfo(VesaInfo:PVesaInfoBlock):Boolean; assembler;
  86.   asm
  87.       push bp
  88.       mov  ax,4F00H
  89.  
  90.      {$IFDEF DPMI}
  91.       mov  bx,VesaInfo.Word+2
  92.       mov  RealModeRegs.TRealRegs.RealES,bx
  93.       mov  di,VesaInfo.Word
  94.       push 10h
  95.       call DPMI.RealModeInterrupt
  96.      {$ELSE}
  97.       les  di,VesaInfo
  98.       int  10h
  99.      {$ENDIF}
  100.  
  101.       cmp  ax,004FH
  102.       mov  al,0
  103.       jnz  @Fin
  104.       inc  al
  105.  
  106.     @Fin:
  107.       pop  bp
  108.   end;
  109.  
  110.  
  111.   (*******************************************************************
  112.     Retrieve VESA video mode information
  113.   *******************************************************************)
  114.   function GetVesaModeInfo(Mode:Word; Buffer:PVesaModeInfo):Boolean; assembler;
  115.   asm
  116.       mov  ax,4F01h
  117.       mov  cx,Mode
  118.  
  119.      {$IFDEF DPMI}
  120.       mov  bx,Buffer.Word+2
  121.       mov  RealModeRegs.TRealRegs.RealES,bx
  122.       mov  di,Buffer.Word
  123.       push 10h
  124.       call DPMI.RealModeInterrupt
  125.      {$ELSE}
  126.       les  di,Buffer
  127.       int  10h
  128.      {$ENDIF}
  129.  
  130.       cmp  ax,004FH
  131.       mov  al,0
  132.       jnz  @Fin
  133.       inc  ax
  134.  
  135.     @Fin:
  136.   end;
  137.  
  138.  
  139.   (*******************************************************************
  140.     Set VESA video mode
  141.   *******************************************************************)
  142.   procedure SetVesaMode(Mode:Word); assembler;
  143.   asm
  144.       mov  ax,4F02h
  145.       mov  bx,Mode
  146.       int  10h
  147.   end;
  148.  
  149.  
  150.   (*******************************************************************
  151.     Retrieve current VESA video mode
  152.   *******************************************************************)
  153.   function GetVesaMode:Word; assembler;
  154.   asm
  155.       mov  ax,4F03h
  156.       int  10h
  157.       xchg ax,bx
  158.   end;
  159.  
  160.  
  161.   (*******************************************************************
  162.     Get VESA version
  163.   *******************************************************************)
  164.   procedure DetectVesaVersion;
  165.     var
  166.      {$IFDEF DPMI}
  167.       VesaInfo      : PVesaInfoBlock;
  168.       RealBufferPtr : PVesaInfoBlock;
  169.      {$ELSE}
  170.       VesaInfo      : VesaInfoBlock;
  171.      {$ENDIF}
  172.   begin
  173.    {$IFDEF DPMI}
  174.     if not GetDosMem(Pointer(RealBufferPtr), Pointer(VesaInfo),
  175.            SizeOf(VesaInfoBlock)) then
  176.       Exit;
  177.     if GetVesaInfo(RealBufferPtr) and (VesaInfo^.VesaSignature=VesaSig) then
  178.       VesaVersion:=VesaInfo^.VesaVersion;
  179.     GlobalDosFree(Seg(VesaInfo^));
  180.    {$ELSE}
  181.     if GetVesaInfo(@VesaInfo) and (VesaInfo.VesaSignature=VesaSig) then
  182.       VesaVersion:=VesaInfo.VesaVersion;
  183.    {$ENDIF}
  184.   end;
  185.  
  186.  
  187.   (*******************************************************************
  188.     Determine available VESA text video modes
  189.   *******************************************************************)
  190.   procedure ScanVesaModes;
  191.     var
  192.       Modes         : ^Word;
  193.      {$IFDEF DPMI}
  194.       BufferPtr     : PVesaModeInfo;
  195.       RealBufferPtr : PVesaModeInfo;
  196.       VesaInfo      : PVesaInfoBlock ABSOLUTE BufferPtr;
  197.      {$ELSE}
  198.       Buffer        : VesaModeInfo;
  199.       VesaInfo      : VesaInfoBlock ABSOLUTE Buffer;
  200.      {$ENDIF}
  201.   begin
  202.    {$IFDEF DPMI}
  203.     if not GetDosMem(Pointer(RealBufferPtr), Pointer(BufferPtr),
  204.            SizeOf(VesaInfoBlock)) then
  205.       Exit;
  206.     GetVesaInfo(PVesaInfoBlock(RealBufferPtr));
  207.     Modes:=DPMI.CreateRealModeSelector(VesaInfo^.VideoModePtr, $FFFF);
  208.    {$ELSE}
  209.     GetVesaInfo(@Buffer);
  210.     Modes:=VesaInfo.VideoModePtr;
  211.    {$ENDIF}
  212.  
  213.     while Modes^<>$FFFF do
  214.     begin
  215.      {$IFDEF DPMI}
  216.       if GetVesaModeInfo(Modes^, RealBufferPtr) then
  217.         with BufferPtr^ do
  218.      {$ELSE}
  219.       if GetVesaModeInfo(Modes^, @Buffer) then
  220.         with Buffer do
  221.      {$ENDIF}
  222.           if (Attr * [Supported, Graphics]) = [Supported] then
  223.             if OptionalInfo in Attr then
  224.               AddMode(Modes^, Height, Width, CharHeight, Color in Attr)
  225.             else
  226.               if Modes^ in [2,3,7] then
  227.                 AddMode(Modes^, 25, 80, 16, Modes^=3);
  228.  
  229.       Inc(Modes);
  230.     end;
  231.  
  232.    {$IFDEF DPMI}
  233.     FreeSelector(Seg(Modes^));
  234.     GlobalDosFree(Seg(BufferPtr^));
  235.    {$ENDIF}
  236.   end;
  237.  
  238.  
  239.   (*******************************************************************
  240.     Used to test if VESA Get Video Mode Info function supported
  241.   *******************************************************************)
  242.   procedure CheckScanSupport(Mode, Rows, Columns, CharHeight:Word; Color:boolean); far;
  243.   begin
  244.     if Mode>7 then
  245.       VesaScanningSupported:=True
  246.     else
  247.       StandardInfoAvailable:=False;
  248.   end;
  249.  
  250.   (*******************************************************************
  251.     Test the hard way if VESA get video mode info function supported
  252.   *******************************************************************)
  253.   function VesaScanningPossible:Boolean;
  254.   begin
  255.     StandardInfoAvailable:=True;
  256.     if VesaVersion<>0 then
  257.       ScanVesaModes(CheckScanSupport);
  258.     StandardInfoAvailable:=not StandardInfoAvailable;
  259.  
  260.     VesaScanningPossible:=VesaScanningSupported;
  261.   end;
  262.  
  263.     (*******************************************************************
  264.     *******************************************************************)
  265.  
  266. end.
  267.